<html>
<head><meta charset="utf-8"><title>Multiple associated types in TyS when the user-written type · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Multiple.20associated.20types.20in.20TyS.20when.20the.20user-written.20type.html">Multiple associated types in TyS when the user-written type</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="224437319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Multiple%20associated%20types%20in%20TyS%20when%20the%20user-written%20type/near/224437319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Multiple.20associated.20types.20in.20TyS.20when.20the.20user-written.20type.html#224437319">(Jan 29 2021 at 07:13)</a>:</h4>
<p>In this program</p>
<div class="codehilite"><pre><span></span><code>trait Restriction {
    type Inner;
}

trait Database: Restriction&lt;Inner = u32&gt; {}

struct Test {}

impl Database for Test {}

impl Restriction for Test {
    type Inner = u32;
}

fn main() {
    let t = Test {};
    let _x: &amp;dyn Database&lt;Inner = _&gt; = &amp;t;
}
</code></pre></div>
<p>If I add some debug prints in mir's type checker I see that the annotated type for <code>_x</code> is <code>&amp;dyn Database&lt;Inner = _, Inner = u32&gt;</code> and normalized type is <code>&amp;dyn Database&lt;Inner = u32, Inner = u32&gt;</code>. I'm confused about why we have two <code>Inner</code>s in these types when the user-written type only has one associated type.</p>
<p>Is this expected? Could anyone point me to some relevant documentation/code?</p>



<a name="224437761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Multiple%20associated%20types%20in%20TyS%20when%20the%20user-written%20type/near/224437761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Multiple.20associated.20types.20in.20TyS.20when.20the.20user-written.20type.html#224437761">(Jan 29 2021 at 07:21)</a>:</h4>
<p><del>It's a bit unfortunate that <code>Ty</code>'s <code>Debug</code> is actually <code>Display</code> so I can't see how exactly this type is represented (which variant of <code>TyKind</code> etc.)</del> Just realized that I can use Debug of kind for this.</p>



<a name="224524124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Multiple%20associated%20types%20in%20TyS%20when%20the%20user-written%20type/near/224524124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Multiple.20associated.20types.20in.20TyS.20when.20the.20user-written.20type.html#224524124">(Jan 29 2021 at 19:49)</a>:</h4>
<p>Anyone?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>